package com.zy.explore.db.infrastructure.plugins.multidbsupport.sqlchange.base;

/**
 * sql语句操作
 * @author xiayd
 *
 */
public class SqlOper implements Comparable<SqlOper> {
	/** 新增 */
	public static final int OPER_ADD = 1;
	/** 删除 */
	public static final int OPER_DELETE = 2;
	/** 替换 */
	public static final int OPER_REPLACE = 3;

	/** 操作类型 */
	private int oper;
	/** 开始位置(包含此位置字符) */
	private int starIdx;
	/** 结束位置(偏移量往后+1) */
	private int endIdx;
	/** 操作字符串 */
	private String str;

	private SqlOper(){

	}
	/** 创建新增 */
	public static SqlOper newAdd(int starIdx,String str){
		SqlOper obj = new SqlOper();
		obj.oper = OPER_ADD;
		obj.starIdx = starIdx;
		obj.str = str;
		return obj;
	}
	/** 创建删除 */
	public static SqlOper newDelete(int starIdx,int endIdx){
		SqlOper obj = new SqlOper();
		obj.oper = OPER_DELETE;
		obj.starIdx = starIdx;
		obj.endIdx = endIdx;
		return obj;
	}
	/** 创建替换 */
	public static SqlOper newReplace(int starIdx,int endIdx,String str){
		SqlOper obj = new SqlOper();
		obj.oper = OPER_REPLACE;
		obj.starIdx = starIdx;
		obj.endIdx = endIdx;
		obj.str = str;
		return obj;
	}

	@Override
	public int compareTo(SqlOper o) {

		return this.starIdx - o.starIdx;
	}

	public int getOper() {
		return oper;
	}
	public int getStarIdx() {
		return starIdx;
	}
	public int getEndIdx() {
		return endIdx;
	}
	public String getStr() {
		return str;
	}

	@Override
	public String toString() {
		return "SqlOper [oper=" + oper + ", starIdx=" + starIdx + ", endIdx=" + endIdx + ", str=" + str + "]";
	}


}
